/**
 * Created by hxpeng on 2017/3/24.
 */
(function () {
    'use strict';

    angular.module('App.common')
        .directive('wxImg', wxImg);


    /**
     * 微信选择图片之后预览，并绑定删除图片
     * @returns {{restrict: string, link: link}}
     */
    function wxImg() {
        return {
            restrict:'E',
            replace :true,
            template:'<li><img class="full-image"><i class="ion-close-circled removeImgBtn"></i></li>',
            link: function(scope, elem, attr) {
                scope.$watch('per',function(nowVal){
                    var img = nowVal;
                    var elem_child = elem[0].childNodes;
                    angular.forEach(elem_child,function(obj){
                        if(obj.nodeName == "IMG"){
                            obj.setAttribute('src',img.url);
                            obj.onclick=function(){
                                scope.previewImg(img.url);
                            }
                        }
                        if(obj.nodeName == "I"){
                            obj.onclick=function(){
                                scope.removePicture(img.url,img.imgIndex);
                            }
                        }

                    })
                })

            }
        };
    }

})();